<template>
  <div>
    <el-row>
      <el-col :span="4" v-for="item in orders" :key="item.id">
        <el-card :body-style="{ padding: '0px' }" shadow="hover" class="md1">
          <img :src="item.photo" class="image">
          <div style="padding: 14px;">
            <span>{{item.goodsName}}</span>
            <div class="bottom clearfix">
              <el-button type="text" @click="getOrderDetail(item.id)">查看详情</el-button>
            </div>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <el-dialog title="订单详情" :visible.sync="dialogFormVisible">
      <el-form :model="orderDetail">
        <el-form-item label="商品名" :label-width="formLabelWidth">
          <el-input v-model="orderDetail.goodsName" autocomplete="off" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="订单编号" :label-width="formLabelWidth">
          <el-input v-model="orderDetail.id" autocomplete="off" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="联系方式" :label-width="formLabelWidth">
          <el-input v-model="orderDetail.tel" autocomplete="off" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="收货地址" :label-width="formLabelWidth">
          <el-input v-model="orderDetail.address" autocomplete="off" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="订单金额" :label-width="formLabelWidth">
          <el-input v-model="orderDetail.price" autocomplete="off" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="购买时间" :label-width="formLabelWidth">
          <el-input v-model="orderDetail.time" autocomplete="off" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="物流信息" :label-width="formLabelWidth">
          <el-input v-model="orderDetail.summary" autocomplete="off" :disabled="true"></el-input>
        </el-form-item>
      </el-form>
      <el-steps :active="orderDetail.state" simple>
        <el-step title="已付款" icon="el-icon-edit"></el-step>
        <el-step title="已发货" icon="el-icon-upload"></el-step>
        <el-step title="签收" icon="el-icon-picture"></el-step>
      </el-steps>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="confirmOrder" :disabled="orderDetail.state=='3'">确认收货</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        orders: [],
        dialogFormVisible: false,
        orderDetail: [],
        formLabelWidth: '120px'
      };
    },
    mounted: function() {
      this.getData()
    },
    methods: {
      getData() {
        this.$axios.post('/getUserOrder', {}).then(resp => {
          this.orders = resp.data
        })
      },
      getOrderDetail(key) {
        this.$axios.post('/orderDetail',{
          id:key
        }).then(resp => {
          this.orderDetail = resp.data
           this.dialogFormVisible=true
        })
      },
      confirmOrder(){
        this.$axios.post('/confirmOrder',{
          id:this.orderDetail.id
        }).then(resp=>{
          if(resp.data.code===200){
            alert("订单完成")
          }
          else{
            alert("出错了")
          }
        })
      }
    }
  }
</script>

<style>
  .bottom {
    margin-top: 13px;
    line-height: 12px;
  }

  .button {
    padding: 0;
    float: right;
  }

  .image {
    height: 200px;
    display: block;
  }

  .clearfix:before,
  .clearfix:after {
    display: table;
    content: "";
  }

  .clearfix:after {
    clear: both
  }

  .md1 {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
  }
</style>
